﻿namespace Creek.UI.EFML.Base.EFML.Elements
{
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Xml;

    public class ScriptElement : ElementBase
    {
        #region Fields

        public string Source;

        #endregion

        #region Public Methods and Operators

        public override void Process(List<ElementBase> Tree, EFMLDocument m)
        {
            Tree.AddRange(
                (from XmlNode script in m.Scripts
                 select
                     new ScriptElement
                         {
                             Source =
                                 script.HasAttribute("src")
                                     ? File.ReadAllText(script.GetAttributeByName("src"))
                                     : script.InnerText
                         }));
        }

        #endregion
    }
}